//

// (  )
//

package com.tools.acceleratecore.xlib.util;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.text.TextUtils;
import java.io.File;

public class UtilApp {
    public UtilApp() {
    }

    public static Drawable getApplicationIcon(Context context, String strPackageName) {
        if (context != null && !TextUtils.isEmpty(strPackageName)) {
            try {
                PackageManager pm = context.getPackageManager();
                ApplicationInfo applicationInfo = pm.getApplicationInfo(strPackageName, 0);
                return applicationInfo.loadIcon(pm);
            } catch (Exception var4) {
                var4.printStackTrace();
                return null;
            }
        } else {
            return null;
        }
    }

    public static String getApplicationName(Context context, String strPackageName) {
        if (context != null && !TextUtils.isEmpty(strPackageName)) {
            try {
                PackageManager pm = context.getPackageManager();
                ApplicationInfo applicationInfo = pm.getApplicationInfo(strPackageName, 0);
                return applicationInfo.loadLabel(pm).toString();
            } catch (Exception var4) {
                var4.printStackTrace();
                return null;
            }
        } else {
            return null;
        }
    }

    public static int getApplicationFlags(Context context, String strPackageName) {
        if (context != null && !TextUtils.isEmpty(strPackageName)) {
            try {
                PackageManager pm = context.getPackageManager();
                ApplicationInfo applicationInfo = pm.getApplicationInfo(strPackageName, 0);
                return applicationInfo.flags;
            } catch (Exception var4) {
                var4.printStackTrace();
                return 0;
            }
        } else {
            return 0;
        }
    }

    public static boolean isSystemApp(Context context, String strPackageName) {
        if (context != null && !TextUtils.isEmpty(strPackageName)) {
            try {
                PackageManager pm = context.getPackageManager();
                ApplicationInfo applicationInfo = pm.getApplicationInfo(strPackageName, 0);
                return (applicationInfo.flags & 1) != 0;
            } catch (Exception var4) {
                var4.printStackTrace();
                return false;
            }
        } else {
            return false;
        }
    }

    public static boolean installApp(Context context, String strApkPath) {
        if (context != null && !TextUtils.isEmpty(strApkPath)) {
            Intent intent = new Intent("android.intent.action.VIEW");
            Uri uri = Uri.fromFile(new File(strApkPath));
            intent.setDataAndType(uri, "application/vnd.android.package-archive");
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);
            return true;
        } else {
            return false;
        }
    }

    public static boolean uninstallApp(Context context, String strPackageName) {
        if (context != null && !TextUtils.isEmpty(strPackageName)) {
            Intent intent = new Intent("android.intent.action.DELETE", Uri.parse(strPackageName));
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);
            return true;
        } else {
            return false;
        }
    }

    public static boolean executeApp(Context context, String strPackageName, String strClassName) {
        if (context != null && !TextUtils.isEmpty(strPackageName) && !TextUtils.isEmpty(strClassName)) {
            Intent intent = new Intent();
            intent.setComponent(new ComponentName(strPackageName, strClassName));
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);
            return true;
        } else {
            return false;
        }
    }

    public static boolean isAppInstalled(Context context, String strPackageName) {
        if (context != null && !TextUtils.isEmpty(strPackageName)) {
            PackageManager pm = context.getPackageManager();

            try {
                pm.getPackageInfo(strPackageName, 0);
                return true;
            } catch (Exception var4) {
                var4.printStackTrace();
                return false;
            }
        } else {
            return false;
        }
    }
}
